package kernel_gui.gui.extended;

import java.awt.Component;
import java.awt.event.ActionEvent;

import javax.swing.JOptionPane;

import kernel_gui.gui.generic.graphic.ControlImport;

@SuppressWarnings("serial")
public class EControlImport extends ControlImport {

	public EControlImport(){
		setExecuteOnCancel(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(true);
				}
			}
		});
		
		setExecuteBeforeLongRequest(new CommandToExecute() {
			
			@Override
			public void command(Object answer) {
				Component components[] = MainPanel.getComponents();
				for (Component c : components) {
					c.setEnabled(false);
				}
				
			}
		});
	}

	@Override
	protected void GenerateQuestionsButtonActionPerformed(ActionEvent evt) {
		
		int userRes = JOptionPane.showConfirmDialog(this, "This should take about 2 minutes.\nContinue?", "", 
				JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
		if(userRes == JOptionPane.YES_OPTION){
			int requestID = executeBeforeLongRequest(new CommandToExecute() {
				
				@Override
				public void command(Object answer) {
					JOptionPane.showMessageDialog(EControlImport.this, "Operation Completed.");
					
				}
			});
		
		
			kernel.generateQuestions(10, requestID);
		}

	}

	@Override
	protected void ImportButtonActionPerformed(ActionEvent evt) {
		int userRes = JOptionPane.showConfirmDialog(this, "This operation can take up to 50 minutes.\nContinue?", "", 
				JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
		if(userRes == JOptionPane.YES_OPTION){
			
			int requestID = executeBeforeLongRequest(new CommandToExecute() {
				
				@Override
				public void command(Object answer) {
					JOptionPane.showMessageDialog(EControlImport.this, "Operation Completed.");
					
				}
			});
		
		
			kernel.importToDB(requestID);
		}

	}

	@Override
	protected void BigUpdateButtonActionPerformed(ActionEvent evt) {
		int userRes = JOptionPane.showConfirmDialog(this, "This operation can take up 30 minutes.\nContinue?", "", 
				JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
		if(userRes == JOptionPane.YES_OPTION){
			
			int requestID = executeBeforeLongRequest(new CommandToExecute() {
				
				@Override
				public void command(Object answer) {
					JOptionPane.showMessageDialog(EControlImport.this, "Operation Completed.");
					
				}
			});
		
		
			kernel.largeUpdate(requestID);
		}

	}

	@Override
	protected void SmallUpdateButtonActionPerformed(ActionEvent evt) {
		int userRes = JOptionPane.showConfirmDialog(this, "This operation can take up to 15 minutes.\nContinue?", "", 
				JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
		if(userRes == JOptionPane.YES_OPTION){
			
			int requestID = executeBeforeLongRequest(new CommandToExecute() {
				
				@Override
				public void command(Object answer) {
					JOptionPane.showMessageDialog(EControlImport.this, "Operation Completed.");
					
				}
			});
		
		
			kernel.smallUpdate(requestID);
		}

	}

	@Override
	protected void BackButtonActionPerformed(ActionEvent evt) {
		openAnotherFrame(EControlPanelMenuFrame.class, true);

	}

	@Override
	protected void setWindowComponentsWhenCalledFromAnotherFrame() {
		/*not needed*/

	}

}
